<!--评价管理-->
<?php

use yii\widgets\LinkPager;
use yii\helpers\Url;
use common\service\ConstatService ;
use backend\service\AuthService ;
use common\service\UtilService ;

$pageName = "评价列表";

$controller = Yii::$app->controller->id;
$action = Yii::$app->controller->action->id;
$this->title = $pageName . "-" . Yii::$app->params['webname'];
$this->params['breadcrumbs'][] = $pageName;
$this->params['display_name'] = $pageName;
$getData = Yii::$app->request->get();

$userId = Yii::$app->admin->identity->user_id ;
$isMobile = UtilService::isMobile() ;

?>

<div class="row">
    <div class="col-md-12">
        <div class="nav-tabs-custom">
            <form id="search_form" style="padding-top: 36px"method="get" action="<?= Url::toRoute(["evalu/index"]) ?>">
                <div class="form-group row" style="padding: 0 19px">
                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0">用户：</label>
                    <div class="col-sm-1" style="padding: 1px">
                        <select class="form-control" name="user_id" id="search_user_id">
                            <option value="-1">全部</option>
                            <?php foreach ($userArr as $key => $val) : ?>
                                <option value="<?= $key ?>"><?= $val ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>

                    <label class="col-sm-1 control-label text-right" style="line-height: 34px; padding: 0" for="w0">评价时间：</label>
                    <div class="col-sm-7" style="padding: 1px">
                        <div style="display: inline-block; <?php if($isMobile==false):?> width: 220px;  <?php endif;?> font-size: 10px">
                            <?= \dosamigos\datepicker\DatePicker::widget([
                                'name' => 'upd_time_start',
                                'language' => 'zh-CN',
                                'value' => empty($getData['upd_time_start']) ? '' :$getData['upd_time_start'] ,
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                ],
                            ]);?>
                        </div>

                        <div style="display: inline-block;  <?php if($isMobile==false):?> width: 220px;  margin-left: 20px; <?php endif;?> font-size: 10px">
                            <?= \dosamigos\datepicker\DatePicker::widget([
                                'name' => 'upd_time_end',
                                'language' => 'zh-CN',
                                'value' => empty($getData['upd_time_end']) ?'' : $getData['upd_time_end'] ,
                                'clientOptions' => [
                                    'autoclose' => true,
                                    'format' => 'yyyy-mm-dd',
                                ],
                            ]);?>
                        </div>
                    </div>

                    <div class="col-sm-2 pull-left">
                        <button class="btn btn-primary" type="submit">搜索</button>
                        <?php if(AuthService::checkUserAuth($userId,"evalu/export")):?>
                        <a href="javascript:void(0)" class="btn btn-success button-order-export-excel">导出</a>
                        <?php endif;?>
                    </div>
                </div>

            </form>
            <div style="border-bottom: 1px solid #ccc; padding: 19px">
                <div style="float: left; color: #666">共  <?= $arr['page']->totalCount ?> 条记录</div>
            </div>
            
            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-bordered table-striped table-condensed">
                            <tbody>
                                <tr>
                                    <th align="center">序号</th>
                                    <th align="center">标题</th>
                                    <th align="center">内容</th>
                                    <th align="center">时间</th>
                                    <th align="center">操作</th>
                                </tr>
                                <?php $page = empty($arr['page']->getPage())?0:$arr['page']->getPage() ;?>
                                <?php $pageSize = empty($arr['page']->pageSize)?$limit:$arr['page']->pageSize ;?>
                                <?php $pageSize = $page * $pageSize ; ?>
                                <?php foreach ($arr['list'] as $key=>$value):?>
                                <tr>
                                    <td><?= $pageSize+$key+1?></td>
                                    <td><?= $value['user_name']; ?>的评价</td>
                                    <td><?= str_replace("|",",",$value['feed']) ?></td>
                                    <td><?= $value['upd_time']; ?></td>
                                    <td>
                                        <?php if(AuthService::checkUserAuth($userId,"evalu/detail")):?>
                                        <?php $detailUrl = Url::to(["/evalu/detail","id"=>$value['id']])?>
                                        <a href="javascript:;" url="<?=$detailUrl?>" class="btn btn-primary btn-xs evalu_detail">查看</a>
                                        <?php endif;?>

                                        <?php if(AuthService::checkUserAuth($userId,"evalu/del")):?>
                                        <?php $delUrl = Url::to(["/evalu/del","id"=>$value['id']])?>
                                        <a href="javascript:ajaxMakedo('<?=$delUrl?>', '确认删除？')" class="btn btn-danger btn-xs">删除</a>
                                        <?php endif;?>
                                    </td>
                                </tr>
                                <?php  endforeach;?>
                                <tr>
                                    <td colspan="20" class="">
                                        <?=
                                        LinkPager::widget([
                                            'firstPageLabel' => '首页',
                                            'lastPageLabel' => '末页',
                                            'prevPageLabel' => '上一页',
                                            'nextPageLabel' => '下一页',
                                            'pagination' => $arr['page'],
                                            'maxButtonCount' => 8,
                                        ])
                                        ?>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function(){
        $("#myModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        }) ;

        var searchGetData = <?= json_encode(Yii::$app->request->get()) ?>;

        if (searchGetData.user_id) {
            $.each(searchGetData, function (key, value) {
                $('#search_' + key + ' option[value="' + value + '"]').attr('selected', 'selected');
            });
        }

        $('.evalu_detail').click(function () {
            var url = $(this).attr("url") ;
            var options = {remote: url};
            $('#myModal').modal(options)
        });

        $('.button-order-export-excel').click(function () {
            var query = $('#search_form').serialize();
            var url = '<?= Url::toRoute(["/evalu/export"]) ?>?' + query;
            $.ajax({
                type: "POST",
                url: url,
                success: function(data){
                    if (typeof(data.code) != "undefined" && data.code == 200) {
//                        console.log(data.url + '?' + query);return;
                        window.open(data.url + '?' + query);
                    } else if (typeof(data.code) != "undefined") {
                        bootboxAlert(data.msg);
                    } else {
                        bootboxAlert('连接异常! ');
                        console.log(data)
                    }
                },
                error: function (data) {
                    if (data.status !=  302) {
                        bootboxAlert(data.responseText);
                    }
                }
            });
        });

    });

</script>